package com.bsj.power.common.def.entity.alarmReport;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.bsj.power.common.def.dto.locationDevice.TagAlarmMsgDTO;
import com.bsj.power.common.def.entity.job.Job;
import com.bsj.power.common.def.entity.job.WorkPersonnel;
import com.bsj.power.common.def.entity.personnel.Personnel;
import com.bsj.power.common.def.vo.pls.httpVo.HttpTagPosVO;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.List;

/**
 * @author LiJiaXin
 * @version 1.0.0
 * @description AlarmReport
 * @time 2024/4/25 17:21
 */
@Data
@TableName(value = "tab_alarm_report")
@NoArgsConstructor
public class AlarmReport {

    /**
     * 报警id
     */
    @TableId(value = "alarm_id", type = IdType.AUTO)
    private Long alarmId;

    /**
     * 设备号
     */
    @TableField("device_name")
    private String deviceName;

    /**
     * 人员类型分类 1:负责人 2:作业人员
     */
    @TableField("person_type")
    private Integer personType;

    /**
     * 人员id
     */
    @TableField("personnel_id")
    private Integer personnelId;

    /**
     * 围栏id
     */
    @TableField("path_id")
    private Integer pathId;

    /**
     * 设备别名
     */
    @TableField("nike_name")
    private String nikeName;

    /**
     * 设备类型（1基站 2UWB 3UWB+北斗）4_GB28181
     */
    @TableField("device_type")
    private Integer deviceType;

    /**
     * 人员姓名
     */
    @TableField("personnel_name")
    private String personnelName;

    /**
     * 围栏名称
     */
    @TableField("path_name")
    private String pathName;

    /**
     * 报警类型 1进围栏报警 2出围栏报警 3异常停留报警 4设备异常离线报警 5组合报警 6人员呼救报警
     */
    @TableField("alarm_type")
    private Integer alarmType;

    /**
     * 报警开始时间
     */
    @TableField("begin_time")
    private Date beginTime;

    /**
     * 报警结束时间
     */
    @TableField("end_time")
    private Date endTime;

    /**
     * 附件存储路径
     */
    @TableField("file_path")
    private String filePath;

    /**
     * 报警开始位置
     */
    @TableField("pos")
    private String pos;

    /**
     * 报警结束位置
     */
    @TableField("end_pos")
    private String endPos;
    /**
     * 报警处理时间
     */
    @TableField("alarm_handle_time")
    private Date alarmHandleTime;

    /**
     * 报警处理状态 1未处理 2已处理
     */
    @TableField("handle_state")
    private Integer handleState;

    /**
     * 处理方式 1语音通报提示 2人工现场处理 3其他
     */
    @TableField("handle_way")
    private Integer handleWay;

    /**
     * 备注
     */
    @TableField("remark")
    private String remark;

    @TableField("alarm_priority")
    private String alarmPriority;

    @TableField("alarm_method")
    private String alarmMethod;

    @TableField("longitude")
    private Double longitude;

    @TableField("latitude")
    private Double latitude;

    /**
     * 事件描述
     */
    @TableField("event_description")
    private String eventDescription;

    /**
     * 响应措施
     */
    @TableField("response_measures")
    private String responseMeasures;

    /**
     * 组合报警名称
     */
    @TableField("com_alarm_name")
    private String comAlarmName;

    /**
     * 摄像头id集
     */
    @TableField(exist = false)
    private List<Long> cameraIds;
    /**
     * 报警时的围栏地址
     */
    @TableField(exist = false)
    private String pathAddress;

    @TableField(exist = false)
    private String beginTimeStr;

    /**
     * 工单信息
     */
    @TableField(exist = false)
    private Job job;

    /**
     * 负责人信息
     */
    @TableField(exist = false)
    private Personnel directorInfo;
    /**
     * 作业人员信息
     */
    @TableField(exist = false)
    private WorkPersonnel workPersonnel;
    /**
     * 警报级别 0普通报警 1:一级报警 2:二级报警
     */
    @TableField(exist = false)
    private Integer alertLevel;

    public AlarmReport(Long alarmId, Date endTime) {
        this.alarmId = alarmId;
        this.endTime = endTime;
    }

    public AlarmReport(String sn, Integer personnelId, Integer pathId, String nikeName, Integer deviceType,
                       String personnelName, String pathName, Integer alarmType, long beginTime, String pos,
                       Integer handleState, Integer personType) {
        this.deviceName = sn;
        this.personnelId = personnelId;
        this.pathId = pathId;
        this.nikeName = nikeName;
        this.deviceType = deviceType;
        this.personnelName = personnelName;
        this.pathName = pathName;
        this.alarmType = alarmType;
        this.beginTime = new Date(beginTime);
        this.pos = pos;
        this.handleState = handleState;
        this.personType = personType;
    }

    public Long duration(long currentTime) {
        long beginT = this.beginTime.getTime();
        long endT;
        if (endTime == null) {
            endT = currentTime;
        } else {
            endT = this.endTime.getTime();
        }
        long div = endT - beginT;
        return div == 0L ? 0L : div / 1000;
    }
}
